import http from '@/utils/axios'
import { Category, PageResType, Article } from '@/types/index'

const findCategories = () => {
  return http.get<Category[]>(`category`)  as unknown as PageResType<Category>
}

const findArticles = (category: string | undefined = undefined) => {
  if (category === undefined) {
    return http.get<Article[]>('article') as unknown as PageResType<Article>
  }
  return http.get<Article[]>(`article/?category=${category}`) as unknown as PageResType<Article>
}

const getArticle = (id: number) => {
  return http.get<Article>(`article/${id}`) as unknown as Article
}

export {
  findCategories, findArticles, getArticle
}

export const API_STATUS_OK = 200
